﻿using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.Linq;
using System.Text;
namespace CovertXMLElement
{
    [XmlRoot("cell-phone")]
    public class CellPhone
    {
        public CellPhone()
        {
        }

        [XmlAttribute("name")]
        public string Name
        {
            get { return this._name; }
            set { this._name = value; }
        }

        [XmlAttribute("year")]
        public int Year
        {
            get { return this._year; }
            set { this._year = value; }
        }

        [XmlElement("description")]
        public string Description
        {
            get { return this._description; }
            set { this._description = value; }
        }
        [XmlElement("children")]
        public Child Children
        {
            get { return this._children; }
            set { this._children = value; }
        }
        private string _name = "";
        private int _year = 2000;
        private string _description = "";
        private Child _children;
    }
    public class Child {
        [XmlElement("name")]
        public string ChildName
        {
            get { return this._childName; }
            set { this._childName = value; }
        }
        [XmlElement("decription")]
        public string ChildDescription
        {
            get { return this._childDescription; }
            set { this._childDescription = value; }
        }
        
        private string _childDescription = "";
        private string _childName = "";
    }
    class Program
    {
        static void Main(string[] args)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(CellPhone));
            CellPhone cellPhone = new CellPhone();
            cellPhone.Description = "Some description";
            cellPhone.Name = "AAA";
            cellPhone.Children = new Child();
            cellPhone.Children.ChildName = "hello";
            cellPhone.Children.ChildDescription = "abc123";
            TextWriter w = new StreamWriter("cellPhone.xml");
            serializer.Serialize(w, cellPhone);
            w.Close();
        }
    }
}
